package pumpeddevs.game.framework;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;

public class PDLoadingBar extends PDSprite{

	private int _numberOfProcess;
	private float _finishProcess;
	private Bitmap _emptyBar;
	private Bitmap _fullBar;
	private int _percentFinish = 1;
	private int _incrementBy;
	private boolean _isFinishLoading;
	
	public void setNumberOfProcess(int numberOfProcess) {
		this._numberOfProcess = numberOfProcess + 1;
	}
	
	public PDLoadingBar(Context context, String[] resourceDrawables) {
		super(context, resourceDrawables);
		
	}
	
	public PDLoadingBar(Context context, int resourceDrawableEmpty, int resourceDrawableFull, int numberOfProcess) {
		super(context);
		this._numberOfProcess = numberOfProcess;
		this._emptyBar = this.getBitmap(resourceDrawableEmpty);
		this._fullBar = this.getBitmap(resourceDrawableFull);
		this._bitmap = this._emptyBar;
		this._incrementBy = this._emptyBar.getWidth() / numberOfProcess;
	}
	
	public void incrementFinishProcess() {
		if(this._finishProcess < this._numberOfProcess) {
			this._finishProcess++;
			this._percentFinish = (int) (this._incrementBy * this._finishProcess);
		}
	}
	
	public void render(Canvas canvas) {
		canvas.drawBitmap(this._emptyBar, this._x, this._y, null);
		
		if(this._finishProcess == this._numberOfProcess) {
			this._percentFinish = this._emptyBar.getWidth();
		}
		
		canvas.drawBitmap(Bitmap.createBitmap(this._fullBar, 0, 0, this._percentFinish,
				this._emptyBar.getHeight()), this._x, this._y, null);
		if(this._finishProcess == this._numberOfProcess) {
			this._isFinishLoading = true;
		}
	}
	
	public boolean isFinishLoading() {
		return this._isFinishLoading;
	}

}
